package middle;

import com.eclipsesource.json.Json;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * 451. 根据字符出现频率排序
 */
public class FrequencySort {

    public static String stringToString(String input) {
        if (input == null) {
            return "null";
        }
        return Json.value(input).toString();
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            String s = stringToString(line);

            String ret = new Solution().frequencySort(s);

            String out = (ret);

            System.out.print(out);
        }
    }

    static class Solution {
        public String frequencySort(String s) {
            char[] chars = s.toCharArray();
            Map<Character,Integer> map = new HashMap<>();
            for (char c:chars){
                map.put(c,map.getOrDefault(c,0)+1);
            }
            List<Character> list = new ArrayList<>(map.keySet());
            Collections.sort(list,(a,b)->map.get(b)-map.get(a));
            StringBuilder sb = new StringBuilder();
            int size = list.size();
            for (Character c:list){
                int count = map.get(c);
                for (int i=0;i<count;i++){
                    sb.append(c);
                }
            }
            return sb.toString();
        }
    }
}
